from PyQt5 import QtCore
from PyQt5.Qt import *

import setting
from ui.form_strategy_list import Ui_FormStrategyList
from page.page_item_strategy import ItemStrategy
class FormStrategyList(QWidget, Ui_FormStrategyList):
    def __init__(self,parent=None):
        super().__init__(parent)
        self.set_ui()
        self.setupUi(self)
        self.resize(744, 95)  # 大小
        self.move(0, 0)  # 位置
        self.frame.setObjectName("frame_box")
        self.is_lock=False
        # 禁止编辑
        self.tw_strategy_list.setEditTriggers(QAbstractItemView.NoEditTriggers)
        # 水平表格头显示和隐藏
        self.tw_strategy_list.horizontalHeader().setVisible(False)
        # 垂直表格头显示和隐藏
        self.tw_strategy_list.verticalHeader().setVisible(False)
        # 隐藏分割线
        self.tw_strategy_list.setShowGrid(False)
        # 隐藏滚动条
        self.tw_strategy_list.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        #self.tw_strategy_list.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.tw_strategy_list.setColumnCount(1)
        self.tw_strategy_list.setSelectionMode(QAbstractItemView.SingleSelection)
    def on_tw_strategy_list_itemSelectionChanged(self):
        if not self.is_lock:
            # 获取选中的项
            self.parent().window_equip.setVisible(True)
            # self.parent().window_location.setVisible(True)
            # self.parent().window_early.setVisible(False)
            self.parent().window_set.cb_equip.setChecked(True)
            # self.parent().window_set.cb_location.setChecked(True)

            self.tw_strategy_list.cellWidget(self.tw_strategy_list.currentIndex().row(),0).update_item(setting.mode)


    def set_ui(self):
        pass
    def add_team(self,strategy=None):
        #增加一行
        new_row_index = self.tw_strategy_list.rowCount()
        self.tw_strategy_list.insertRow(new_row_index)
        item_strategy = ItemStrategy(self)
        item_strategy.set_strategy(strategy)
        self.tw_strategy_list.setCellWidget(new_row_index,0 , item_strategy)
    def set_teams(self,strategy_list:list):
        '''
        设置队伍
        :param chess_datas:
        :return:
        '''

        if len(strategy_list)==0:
            return
        # 清空列表
        self.is_lock=True
        self.tw_strategy_list.setRowCount(0)
        self.tw_strategy_list.clear()
        for item in strategy_list:

            self.add_team(item)
        self.is_lock = False
    def test(self):
        '''
        测试展示
        :return:
        '''
        for i in range(10):
            self.add_team(None)


